package net.lgy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  // 允许所有接口
                // 关键修正：用一个allowedOrigins()传入多个域名
                .allowedOrigins("http://localhost:5173", "http://www.lgy-cloud.site","http://lgy-introduce.cloud/"
                ,"http://115.190.152.173","http://192.168.0.3:8080","http://lgy-cloud.site","http://localhost:5175"
                        ,"http://localhost:3000","http://localhost:3001")
                .allowedMethods("GET", "POST", "PUT", "DELETE")  // 允许的请求方法
                .allowedHeaders("*")  // 允许的请求头
                .allowCredentials(true)  // 允许携带Cookie
                .maxAge(3600);  // 预检请求有效期（秒）
    }
}
